#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

#define flr(x,l,r) for (int x = l; x <= r; ++ x)
#define frl(x,r,l) for (int x = r; x >= l; -- x)
#define szf sizeof
#define in(x) scanf("%d", &x)
#define out(x) printf("%d", x)
#define pn printf("\n")
#define con continue
#define bk break
#define vc vector 
#define pb push_back
#define sz size

using namespace std;

const int N = 35;

int f[N][10];

void init() {
    flr (j, 0, 9) if (j != 4) f[1][j] = 1;
    
    flr (i, 1, N)
        flr (j, 0, 9) {
            if (j == 4) con;
            flr (k, 0, 9)
                if (k == 4 || (j == 6 && k == 2)) con;
                else f[i][j] += f[i - 1][k];
        }
}

int dp(int n) {
    if (!n) return 1;
    
    vc<int> nums;
    while (n) nums.pb(n % 10), n /= 10;
    
    int res = 0, last = 0;
    frl (i, nums.sz() - 1, 0) {
        int x = nums[i];
        
        flr (j, 0, x - 1)
            if (j == 4 || (last == 6 && j == 2)) con;
            else res += f[i + 1][j];
        
        if (x == 4 || (last == 6 && x == 2)) bk;
        last = x;
        
        if (!i) res ++ ;
    }
    
    return res;
}

int main() {
	int l, r;
	
	init();
	while (cin >> l >> r, l || r) out(dp(r) - dp(l - 1)), pn;
	
	return 0;
}